<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="功能名称" prop="functionName">
        <el-input
          v-model="queryParams.functionName"
          placeholder="请输入功能名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:assist:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:assist:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:assist:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:assist:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="assistList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="功能名称" align="center" prop="functionName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.function_name" :value="scope.row.functionName"/>
        </template>
      </el-table-column>
      <el-table-column label="功能说明" align="center" prop="functionDesc"/>
      <el-table-column label="处理内容标识名称" align="center" prop="dealFlagName"/>
<!--      <el-table-column label="处理内容标识列" align="center" prop="dealFlagColumn"/>
      <el-table-column label="需要过滤文本所在列" align="center" prop="filterTextColumn"/>-->
      <el-table-column label="要过滤的文本内容" align="center" :show-overflow-tooltip="true" prop="filterTextContent"/>
<!--      <el-table-column label="处理内容所在列" align="center" prop="dealTextColumn"/>-->
      <el-table-column label="矩形背景色(RGB)" align="center" prop="rectangleBackColor"/>
      <el-table-column label="布局类型" align="center" prop="layoutType"/>
      <el-table-column label="字体名称" align="center" prop="fontPath"/>
      <el-table-column label="原文件路径" align="center" prop="originalFilePath"/>
      <el-table-column label="现文件路径" align="center" prop="targetFilePath"/>
<!--      <el-table-column label="字体样式" align="center" prop="fontStyle"/>
      <el-table-column label="字体颜色(RGB)" align="center" prop="fontColor"/>
      <el-table-column label="字体大小" align="center" prop="fontSize"/>
      <el-table-column label="默认高度" align="center" prop="defualtHeight"/>
      <el-table-column label="修改框高度" align="center" prop="modifyBoxHeight"/>
      <el-table-column label="修改框宽度" align="center" prop="modifyBoxWidth"/>
      <el-table-column label="X轴偏移量" align="center" prop="offsetX"/>
      <el-table-column label="Y轴偏移量" align="center" prop="offsetY"/>-->
      <el-table-column label="备注信息" align="center" prop="remarks"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:assist:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:assist:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改数据配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="功能名称" prop="functionName">
          <el-input v-model="form.functionName" placeholder="请输入功能名称"/>
        </el-form-item>
        <el-form-item label="功能说明" prop="functionDesc">
          <el-input v-model="form.functionDesc" placeholder="请输入功能说明"/>
        </el-form-item>
        <el-form-item label="处理内容标识名称" prop="dealFlagName">
          <el-input v-model="form.dealFlagName" placeholder="请输入处理内容标识名称"/>
        </el-form-item>
        <el-form-item label="处理内容标识列" prop="dealFlagColumn">
          <el-input v-model="form.dealFlagColumn" placeholder="请输入处理内容标识列"/>
        </el-form-item>
        <el-form-item label="需要过滤文本所在列" prop="filterTextColumn">
          <el-input v-model="form.filterTextColumn" placeholder="请输入需要过滤文本所在列"/>
        </el-form-item>
        <el-form-item label="要过滤的文本内容" prop="filterTextContent">
          <el-input v-model="form.filterTextContent" placeholder="请输入要过滤的文本内容"/>
        </el-form-item>
        <el-form-item label="处理内容所在列" prop="dealTextColumn">
          <el-input v-model="form.dealTextColumn" placeholder="请输入处理内容所在列"/>
        </el-form-item>
        <el-form-item label="矩形背景色" prop="rectangleBackColor">
          <el-input v-model="form.rectangleBackColor" placeholder="请输入矩形背景色"/>
        </el-form-item>
        <el-form-item label="原文件路径" prop="originalFilePath">
          <el-input v-model="form.originalFilePath" placeholder="请输入原文件路径"/>
        </el-form-item>
        <el-form-item label="现文件路径" prop="targetFilePath">
          <el-input v-model="form.targetFilePath" placeholder="请输入现文件路径"/>
        </el-form-item>
        <el-form-item label="布局类型" prop="layoutType">
          <el-input v-model="form.layoutType" placeholder="请输入布局类型"/>
        </el-form-item>
        <el-form-item label="字体位置或名称" prop="fontPath">
          <el-input v-model="form.fontPath" placeholder="请输入字体位置或名称"/>
        </el-form-item>
        <el-form-item label="字体样式" prop="fontStyle">
          <el-input v-model="form.fontStyle" placeholder="请输入字体样式"/>
        </el-form-item>
        <el-form-item label="字体颜色" prop="fontColor">
          <el-input v-model="form.fontColor" placeholder="请输入字体颜色"/>
        </el-form-item>
        <el-form-item label="字体大小" prop="fontSize">
          <el-input v-model="form.fontSize" placeholder="请输入字体大小"/>
        </el-form-item>
        <el-form-item label="默认高度" prop="defualtHeight">
          <el-input v-model="form.defualtHeight" placeholder="请输入默认高度"/>
        </el-form-item>
        <el-form-item label="修改框高度" prop="modifyBoxHeight">
          <el-input v-model="form.modifyBoxHeight" placeholder="请输入修改框高度"/>
        </el-form-item>
        <el-form-item label="修改框宽度" prop="modifyBoxWidth">
          <el-input v-model="form.modifyBoxWidth" placeholder="请输入修改框宽度"/>
        </el-form-item>
        <el-form-item label="X轴偏移量" prop="offsetX">
          <el-input v-model="form.offsetX" placeholder="请输入X轴偏移量"/>
        </el-form-item>
        <el-form-item label="Y轴偏移量" prop="offsetY">
          <el-input v-model="form.offsetY" placeholder="请输入Y轴偏移量"/>
        </el-form-item>
        <el-form-item label="备注信息" prop="remarks">
          <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listAssist, getAssist, delAssist, addAssist, updateAssist} from "@/api/system/assist";

export default {
  name: "Assist",
  dicts: ['function_name'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 数据配置表格数据
      assistList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        functionName: null,
        functionDesc: null,
        dealFlagName: null,
        dealFlagColumn: null,
        filterTextColumn: null,
        filterTextContent: null,
        dealTextColumn: null,
        rectangleBackColor: null,
        layoutType: null,
        fontPath: null,
        fontStyle: null,
        fontColor: null,
        fontSize: null,
        defualtHeight: null,
        modifyBoxHeight: null,
        modifyBoxWidth: null,
        offsetX: null,
        offsetY: null,
        remarks: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询数据配置列表 */
    getList() {
      this.loading = true;
      listAssist(this.queryParams).then(response => {
        this.assistList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        functionName: null,
        functionDesc: null,
        dealFlagName: null,
        dealFlagColumn: null,
        filterTextColumn: null,
        filterTextContent: null,
        dealTextColumn: null,
        rectangleBackColor: null,
        originalFilePath: null,
        targetFilePath: null,
        layoutType: null,
        fontPath: null,
        fontStyle: null,
        fontColor: null,
        fontSize: null,
        defualtHeight: null,
        modifyBoxHeight: null,
        modifyBoxWidth: null,
        offsetX: null,
        offsetY: null,
        createTime: null,
        updateTime: null,
        remarks: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加数据配置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAssist(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改数据配置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAssist(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAssist(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据配置编号为"' + ids + '"的数据项？').then(function () {
        return delAssist(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/assist/export', {
        ...this.queryParams
      }, `assist_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
